import axios from './config'

export async function getAllOfflineBooks () {
  return axios.get('/l/book')
}

export async function downloadBook (bookName) {
  return axios.get(`/l/book/${bookName}`, {
    responseType: 'blob',
    timeout: 1000 * 60 * 10
  })
}

export async function getAllUids () {
  return axios.get('/l/uids')
}

export async function getAllBooksByUid (uid) {
  return axios.get(`/l/book/${uid}/uid`, {
    timeout: 1000 * 60 * 5
  })
}

export async function deleteBooksByUid (uid, bids) {
  let bidStr = '0'
  if (bids.length) {
    for (let i = 0; i < bids.length; i++) {
      bidStr += `, ${bids[i]}`
    }
    return axios.delete(`/l/book/${uid}/uid?bids=${bidStr}`)
  } else {
    return 'success'
  }
}
